package com.ebelter.seneo.ui.fragments.infos;


import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.ebelter.btcomlib.common.IOrder;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.seneo.R;
import com.ebelter.seneo.contants.IUserContant;
import com.ebelter.seneo.ui.fragments.BaseFragment;
import com.ebelter.seneo.ui.fragments.main.Info_Fragment;
import com.ebelter.seneo.ui.views.LevelView;
import com.ebelter.seneo.utils.BodyCompositionCriteria;
import com.ebelter.seneo.utils.SeneoUtils;


//填写密码
public class Info_Size_Fragment extends BaseFragment  implements Info_Fragment.IInfoUpdateInterface {

    public static final String TAG = "Info_Size_Fragment";
    TextView infofly_value_tv;
    TextView infofly_valueunit_tv;
    TextView infofly_tip1_tv;


    @Override
    protected int setLayoutResouceId() {
        return R.layout.info_fly2;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        infofly_value_tv=findViewById(R.id.infofly_value_tv);
        infofly_valueunit_tv=findViewById(R.id.infofly_valueunit_tv);
        infofly_tip1_tv=findViewById(R.id.infofly_tip1_tv);

    }


    @Override
    protected void initData(Bundle arguments) {

        String tip=getString(R.string.info_size_tip);
        infofly_tip1_tv.setText(tip);

        //执行了这一句 下面的UpdateCurrentMesureInfo接口会回调display方法
        if (getParentFragment()!=null){
            ((Info_Fragment)getParentFragment()).getCurrentDisplayInfo(TAG);
        }
    }



    @Override
    public void UpdateCurrentMesureInfo(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {

        disSize(currentUserinfos,currentMeasureRecord);
    }

    private void disSize(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        if (currentUserinfos==null){
            return;
        }
        if (currentMeasureRecord!=null){
            if (currentMeasureRecord.muscleVolume!=0&&currentMeasureRecord.fat!=0){
                int year = SeneoUtils.getBirthdayIntValue(currentUserinfos.birthday,0,1991);
                int age = SeneoUtils.getAgeByBirthday(year);
                int sex=currentUserinfos.sex;
                int height = currentUserinfos.height;

                Object[] objects=BodyCompositionCriteria.getSize(currentMeasureRecord.fat,age,sex,currentMeasureRecord.muscleVolume,height);
                ViewUtils.setTextViewStr(infofly_value_tv, (String) objects[1]);

            }else if (currentMeasureRecord.skeletalMuscle == 0){
                ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
            }

        }else {
            ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
        }
    }
}
